/*
 *  Copyright 2012 yura.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.odg.dg.incomingdata;

import java.io.Serializable;
import org.apache.commons.lang.StringUtils;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Root;

/**
 *
 * @author yura
 */
@Root(name="databaseSettings")
public class DatabaseSettings implements Cloneable, Serializable {

    @Attribute
    private String url;
    @Attribute
    private String driver;
    @Attribute(required=false)
    private String user;
    @Attribute(required=false)
    private String pswd;

    private DatabaseSettings() {
        // for simple framework
    }

    public DatabaseSettings(String url, String driver, String user, String pswd) {
        this.url = url;
        this.driver = driver;
        this.user = user;
        this.pswd = pswd;
    }

    public String getDriver() {
        return driver;
    }

    public void setDriver(String driver) {
        this.driver = driver;
    }

    public String getPswd() {
        return pswd;
    }

    public void setPswd(String pswd) {
        this.pswd = pswd;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUser() {
        return user;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public boolean isEmpty() {
        return StringUtils.isEmpty(url) && StringUtils.isEmpty(driver)
                && StringUtils.isEmpty(user) && StringUtils.isEmpty(pswd);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final DatabaseSettings other = (DatabaseSettings) obj;
        if ((this.url == null) ? (other.url != null) : !this.url.equals(other.url)) {
            return false;
        }
        if ((this.driver == null) ? (other.driver != null) : !this.driver.equals(other.driver)) {
            return false;
        }
        if ((this.user == null) ? (other.user != null) : !this.user.equals(other.user)) {
            return false;
        }
        if ((this.pswd == null) ? (other.pswd != null) : !this.pswd.equals(other.pswd)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 29 * hash + (this.url != null ? this.url.hashCode() : 0);
        hash = 29 * hash + (this.driver != null ? this.driver.hashCode() : 0);
        hash = 29 * hash + (this.user != null ? this.user.hashCode() : 0);
        hash = 29 * hash + (this.pswd != null ? this.pswd.hashCode() : 0);
        return hash;
    }

    @Override
    public DatabaseSettings clone() {
        return new DatabaseSettings(url, driver, user, pswd);
    }

    @Override
    public String toString() {
        return "DatabaseSettings{" + "url=" + url + "; driver=" + driver
                + "; user=" + user + "; pswd=" + pswd + '}';
    }

}
